﻿using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using HRM.HRMServiceProxy;
using WeifenLuo.WinFormsUI.Docking;

namespace HRM
{
    public partial class frmCRList : DockContent
    {
        int pageSize = UIParamater.pageSize;
        int currPage = 0;
        int itemCount = 0;
        int totalPage = 0;
        int RecruitmentID = 0;
        int CRID = 0;
        RecruitmentClient wcfRecruitment;
        RecruitmentInfo _RecruitmentInfo;
        CRClient wcfCR;

        RoleRightInfo listRole;
        public frmCRList()
        {
            InitializeComponent();
            UISetting.LoadYears(ref CboYears);            
            LoadLanguage();
            UseInitializeComponent();
            BuildVoucherGrid();           

            listRole = UIParamater.Quyen_DotTuyenDung;
            if (!listRole._create)
                btnNew.Enabled = false;
            if (!listRole._delete)
                btnDel.Enabled = false;
            if (!listRole.Update)
            {
                this.btnEdit.Image = global::HRM.Properties.Resources.app;
                this.btnEdit.Tag = "xem";

                this.btnEdit_CR.Image = global::HRM.Properties.Resources.app;
                this.btnEdit_CR.Tag = "xem";
            }
            else
            {
                this.btnEdit.Image = global::HRM.Properties.Resources.edit;
                this.btnEdit.Tag = "sua";

                this.btnEdit_CR.Image = global::HRM.Properties.Resources.edit;
                this.btnEdit_CR.Tag = "sua";
            }
            //LoadYears();
            
            LoadTreeView();
            tvRecruitment.Tag = 0;
            UISetting.NapTrangThaiHoSo(ref cboStatus);
            cboStatus.ComboBox.SelectedIndex = 0;
            LoadData();
        }
       
        
        void LoadLanguage()
        {
            if (this.Tag != null)
                this.Text = this.TabText = UpdateUI.GetString(this.Tag.ToString());
            UpdateUI.Load_ToolStrip(ref toolStrip1);
            UpdateUI.Load_ToolStrip(ref toolStrip2);
            UpdateUI.Load_ToolStrip(ref toolStrip3);
        }
        private void UseInitializeComponent()
        {
            wcfRecruitment = Service.Recruitment();

            _RecruitmentInfo = new RecruitmentInfo();

            wcfCR = Service.CR();
        }
        #region Recruitment's
        private void LoadTreeView()
        {
            //tvRecruitment.BackColor = Color.White;
            tvRecruitment.Nodes.Clear();
            tvRecruitment.Nodes.Add("Root", UpdateUI.GetString("dottuyendung"), 1, 1).Tag = 0;

            {
                wcfRecruitment = Service.Recruitment();
                DataTable dt = new DataTable();
                if (CboYears.Text.Length == 0)
                    dt = wcfRecruitment.Recruitment_GetAll(DateTime.Now.Year).Tables[0];
                else
                    dt = wcfRecruitment.Recruitment_GetAll(Convert.ToInt32(CboYears.Text)).Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    tvRecruitment.Nodes["Root"].Nodes.Add
                        (
                        dr["Recruitment_ID"].ToString(),
                        dr["Recruitment_Name"].ToString(), 2, 3
                        ).Tag = Convert.ToInt32(dr["Recruitment_ID"]);

                }
            }
            tvRecruitment.Nodes["Root"].ExpandAll();
            tvRecruitment.Select();
        }


        private void tvRecruitment_AfterSelect(object sender, TreeViewEventArgs e)
        {
            RecruitmentID = Convert.ToInt32(e.Node.Tag);
            if (RecruitmentID > 0)
            {
                _RecruitmentInfo = wcfRecruitment.Recruitment_GetInfo(RecruitmentID);
                toolStripLabel4.Text = _RecruitmentInfo.Name.ToUpper();
            }
            else
                toolStripLabel4.Text = "";
            LoadData();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            if (!listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            Form f = new frmRecruitment(0, listRole);
            if (f.ShowDialog(this) == DialogResult.OK)
            {
                LoadTreeView();
            }
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (RecruitmentID > 0)
            {
                if (!listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (wcfRecruitment.Recruitment_Using(RecruitmentID) != 0)
                {
                    MessageBox.Show(UpdateUI.GetString("dasudung"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (wcfRecruitment.Recruitment_Delete(RecruitmentID))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadTreeView();
                        LoadData();
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (RecruitmentID > 0)
            {
                if (listRole.Update || listRole.View)
                {

                    Form f = new frmRecruitment(RecruitmentID, listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadTreeView();
                    }
                }
                else
                    Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("khongcoquyenxem"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
            }
        }


        #endregion

        #region CR's

        private void BuildVoucherGrid()
        {
            UISetting.AddColumn(ref dgvList, "CR_ID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvList, "CR_CandidateID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvList, "CR_RecruitmentID", "Mã chính", "", 1, false, true);
            UISetting.AddColumn(ref dgvList, "RowNumber", UpdateUI.GetString("stt"), "C", 50, true, true);
            UISetting.AddColumn(ref dgvList, "Candidate_No", UpdateUI.GetString("maso"), "", 100, true, true);
            UISetting.AddColumn(ref dgvList, "Candidate_FullName", UpdateUI.GetString("hovaten"), "", 130, true, true);
            UISetting.AddColumn(ref dgvList, "Candidate_Sex", UpdateUI.GetString("gioitinh"), "C", 90, true, true);
            UISetting.AddColumn(ref dgvList, "Candidate_DateOfBirth", UpdateUI.GetString("ngaysinh"), "C", 100, true, true);
            UISetting.AddColumn(ref dgvList, "Candidate_PlaceOfBirth", UpdateUI.GetString("noisinh"), "", 130, true, true);
            UISetting.AddColumn(ref dgvList, "Candidate_IDCardNo", UpdateUI.GetString("CMTND"), "", 100, true, true);
            UISetting.AddColumn(ref dgvList, "Candidate_Address", UpdateUI.GetString("diachi"), "", 100, true, true);
            UISetting.AddColumn(ref dgvList, "Candidate_Phone", UpdateUI.GetString("dienthoai"), "", 100, true, true);
            UISetting.AddColumn(ref dgvList, "Candidate_Date", UpdateUI.GetString("ngaynophoso"), "", 120, true, true);
            UISetting.AddColumn(ref dgvList, "Recruitment_Name", UpdateUI.GetString("dottuyendung"), "", 150, true, true);
            UISetting.AddColumn(ref dgvList, "CR_Status", "", "", 1, false, true);
        }
        private void LoadData()
        {
            string keyWord = "";
            if (txtKeyWord.Text.Trim().Contains("'"))
                keyWord = txtKeyWord.Text.Trim().Replace("'", "''");
            else
                keyWord = txtKeyWord.Text.Trim();
            int _Status = Convert.ToInt32(cboStatus.ComboBox.SelectedValue);

            DataSet _ds = wcfCR.CR_GetList(out itemCount, _Status, keyWord, RecruitmentID, currPage, pageSize);

            PageIndex();

            dgvList.Rows.Clear();
            if (_ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
                {
                    dgvList.Rows.Insert(i, 1);
                    dgvList.Rows[i].Cells["CR_ID"].Value = _ds.Tables[0].Rows[i]["CR_ID"].ToString();
                    dgvList.Rows[i].Cells["CR_CandidateID"].Value = _ds.Tables[0].Rows[i]["CR_CandidateID"].ToString();
                    dgvList.Rows[i].Cells["CR_RecruitmentID"].Value = _ds.Tables[0].Rows[i]["CR_RecruitmentID"].ToString();
                    dgvList.Rows[i].Cells["RowNumber"].Value = _ds.Tables[0].Rows[i]["RowNumber"].ToString();
                    dgvList.Rows[i].Cells["Candidate_No"].Value = _ds.Tables[0].Rows[i]["Candidate_No"].ToString();
                    dgvList.Rows[i].Cells["Candidate_FullName"].Value = _ds.Tables[0].Rows[i]["Candidate_LastName"].ToString() + " " + _ds.Tables[0].Rows[i]["Candidate_FirstName"].ToString();
                    dgvList.Rows[i].Cells["Candidate_Sex"].Value = _ds.Tables[0].Rows[i]["Candidate_Sex"].ToString();                     
                    dgvList.Rows[i].Cells["Candidate_DateOfBirth"].Value = Convert.ToDateTime(_ds.Tables[0].Rows[i]["Candidate_DateOfBirth"]).ToString("dd/MM/yyyy");
                    dgvList.Rows[i].Cells["Candidate_PlaceOfBirth"].Value = _ds.Tables[0].Rows[i]["Candidate_PlaceOfBirth"].ToString();
                    dgvList.Rows[i].Cells["Candidate_IDCardNo"].Value = _ds.Tables[0].Rows[i]["Candidate_IDCardNo"].ToString();
                    dgvList.Rows[i].Cells["Candidate_Address"].Value = _ds.Tables[0].Rows[i]["Candidate_Address"].ToString();
                    dgvList.Rows[i].Cells["Candidate_Phone"].Value = _ds.Tables[0].Rows[i]["Candidate_Phone"].ToString();
                    dgvList.Rows[i].Cells["Recruitment_Name"].Value = _ds.Tables[0].Rows[i]["Recruitment_Name"].ToString();
                    if (_ds.Tables[0].Rows[i]["Candidate_Date"] != DBNull.Value)
                        dgvList.Rows[i].Cells["Candidate_Date"].Value = Convert.ToDateTime(_ds.Tables[0].Rows[i]["Candidate_Date"]).ToString("dd/MM/yyyy");
                    dgvList.Rows[i].Cells["CR_Status"].Value = _ds.Tables[0].Rows[i]["CR_Status"].ToString();
                }
            }
        }
        private void PageIndex()
        {
            totalPage = itemCount % pageSize > 0 ? (itemCount / pageSize) + 1 : (itemCount / pageSize);
            if (totalPage == 0)
                lblPageIndex.Text = "0" + "/" + totalPage.ToString();
            else
                lblPageIndex.Text = (currPage + 1).ToString() + "/" + totalPage.ToString();
        }



        private void btnFisrt_CR_Click(object sender, EventArgs e)
        {
            currPage = 0;
            LoadData();
        }

        private void btnNext_CR_Click(object sender, EventArgs e)
        {
            totalPage = itemCount % pageSize > 0 ? (itemCount / pageSize) + 1 : (itemCount / pageSize);
            if (totalPage > 0 && currPage != totalPage - 1)
                currPage++;
            LoadData();
        }

        private void btnPrevious_CR_Click(object sender, EventArgs e)
        {
            if (currPage != 0)
                currPage--;
            LoadData();
        }

        private void btnLast_CR_Click(object sender, EventArgs e)
        {
            totalPage = itemCount % pageSize > 0 ? (itemCount / pageSize) + 1 : (itemCount / pageSize);
            if (totalPage != 0)
                currPage = totalPage - 1;
            LoadData();
        }

        private void dgvList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
                btnEdit_CR_Click(null, null);
        }



        private void txtKeyWord_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                btnFind_Click(null, null);
        }

        private void btnFind_Click(object sender, EventArgs e)
        {
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            style.Alignment = DataGridViewContentAlignment.MiddleCenter;
            style.ForeColor = Color.IndianRed;
            style.BackColor = Color.Ivory;

            foreach (DataGridViewColumn column in dgvList.Columns)
            {
                //column.HeaderCell.Value = column.Index.ToString();
                column.HeaderCell.Style = style;
            }
            currPage = 0;
            LoadData();
        }

        private void btnDel_CR_Click(object sender, EventArgs e)
        {
            if (dgvList.SelectedRows.Count > 0)
            {
                if (!listRole.Delete)
                {
                    MessageBox.Show(UpdateUI.GetString("khongcoquyenxoa"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                CRID = Convert.ToInt32(dgvList.SelectedRows[0].Cells["CR_ID"].Value);
                if (MessageBox.Show(UpdateUI.GetString("bancochacchanxoa"), UIParamater.TitleProject, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (wcfCR.CR_Delete(CRID))
                    {
                        Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("xoathanhcong"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
                        LoadData();
                    }
                    else
                    {
                        MessageBox.Show(UpdateUI.GetString("xoakhongthanhcong"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }

        private void btnEdit_CR_Click(object sender, EventArgs e)
        {
            if (dgvList.SelectedRows.Count > 0)
            {
                if (listRole.Update || listRole.View)
                {

                    CRID = Convert.ToInt32(dgvList.SelectedRows[0].Cells["CR_ID"].Value);
                    int _ReID = Convert.ToInt32(dgvList.SelectedRows[0].Cells["CR_RecruitmentID"].Value);
                    Form f = new frmCR(CRID, _ReID, listRole);
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        LoadData();
                    }
                }
                else
                    Program.taskbarNotifier.Show(UIParamater.TitleProject, UpdateUI.GetString("khongcoquyenxem"), UIParamater.TIME_MOVE_UP, UIParamater.TIME_SHOW, UIParamater.TIME_MOVE_DOWN);
            }
        }

        private void btnNew_CR_Click(object sender, EventArgs e)
        {
            if (!listRole.Create)
            {
                MessageBox.Show(UpdateUI.GetString("khongcoquyenthemmoi"), UIParamater.TitleProject, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            Form f = new Form();
            if (RecruitmentID > 0)
                f = new frmCR(0, RecruitmentID, listRole);
            else
                f = new frmCR(0, 0, listRole);
            if (f.ShowDialog(this) == DialogResult.OK)
            {
                currPage = 0;
                LoadData();
            }
        }
        #endregion

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            btnNew_CR_Click(null, null);
        }

        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            btnEdit_CR_Click(null, null);
        }

        private void delToolStripMenuItem_Click(object sender, EventArgs e)
        {
            btnDel_CR_Click(null, null);
        }


        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            btnNew_Click(null, null);
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            btnEdit_Click(null, null);
        }

        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            btnDel_Click(null, null);
        }

        private void frmCRList_Activated(object sender, EventArgs e)
        {
            LoadLanguage();
            if (dgvList.Columns.Count > 0)
            {
                dgvList.Columns["RowNumber"].HeaderText = UpdateUI.GetString("stt");
                dgvList.Columns["Candidate_No"].HeaderText = UpdateUI.GetString("maso");
                dgvList.Columns["Candidate_FullName"].HeaderText = UpdateUI.GetString("hovaten");
                dgvList.Columns["Candidate_DateOfBirth"].HeaderText = UpdateUI.GetString("ngaysinh");
                dgvList.Columns["Candidate_PlaceOfBirth"].HeaderText = UpdateUI.GetString("noisinh");
                dgvList.Columns["Candidate_Address"].HeaderText = UpdateUI.GetString("diachi");
                dgvList.Columns["Candidate_Phone"].HeaderText = UpdateUI.GetString("dienthoai");
                dgvList.Columns["Candidate_Sex"].HeaderText = UpdateUI.GetString("gioitinh");
                dgvList.Columns["Candidate_IDCardNo"].HeaderText = UpdateUI.GetString("CMTND");
                dgvList.Columns["Candidate_Date"].HeaderText = UpdateUI.GetString("ngaynophoso");
                dgvList.Columns["Recruitment_Name"].HeaderText = UpdateUI.GetString("dottuyendung");
            }

        }

        private void cboStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            int _status = Convert.ToInt32(cboStatus.ComboBox.SelectedValue);
            if (_status == 8 || _status == 6 || _status == 3 || _status == 5 || _status == 7)
            {
                btnDel_CR.Enabled = false;
                btnEdit_CR.Tag = "xem";
                this.btnEdit_CR.Image = global::HRM.Properties.Resources.app;
            }
            else
            {
                btnDel_CR.Enabled = true;
                this.btnEdit_CR.Image = global::HRM.Properties.Resources.edit;
                btnEdit_CR.Tag = "sua";
            }
            LoadLanguage();
            currPage = 0;
            LoadData();
        }

        private void cboYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (CboYears.Text.Length > 0)
                LoadTreeView();
        }

        private void dgvList_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvList.Rows.Count > 0)
            {
                int _status = Convert.ToInt32(dgvList.CurrentRow.Cells["CR_Status"].Value);
                //if (_status == 8 || _status == 6 || _status == 3 || _status == 5 || _status == 7)
                //{
                //    btnDel_CR.Enabled = false;
                //    btnEdit_CR.Tag = "xem";
                //    this.btnEdit_CR.Image = global::HRM.Properties.Resources.app;
                //}
                //else
                //{
                //    btnDel_CR.Enabled = true;
                //    this.btnEdit_CR.Image = global::HRM.Properties.Resources.edit;
                //    btnEdit_CR.Tag = "sua";
                //}
            }
        }

        private void frmCRList_FormClosing(object sender, FormClosingEventArgs e)
        {
            wcfCR.Close();
            wcfRecruitment.Close();
        }

        private void cboYear_Click(object sender, EventArgs e)
        {

        }

        private void btnExcel_Click(object sender, EventArgs e)
        {

            string keyWord = "";
            if (txtKeyWord.Text.Trim().Contains("'"))
                keyWord = txtKeyWord.Text.Trim().Replace("'", "''");
            else
                keyWord = txtKeyWord.Text.Trim();
            int _StatusID = Convert.ToInt32(cboStatus.ComboBox.SelectedValue);
                 DataSet ds = new DataSet();
            string _fileName = "";
            _fileName = "tmpUngTuyen.xls";
            try
            { 
                    if (_StatusID == 0)
                     //tất cả
                        ds = wcfCR.CR_GetList(out itemCount,0, keyWord, RecruitmentID, currPage, pageSize);
                    else if (_StatusID == 1)
                        //Nhập hồ sơ
                        ds = wcfCR.CR_GetList(out itemCount, 1, keyWord, RecruitmentID, currPage, pageSize);
                    else if (_StatusID == 2)
                    //pv lan 1
                    ds = wcfCR.CR_GetList(out itemCount, 2, keyWord, RecruitmentID, currPage, pageSize);
                    else if (_StatusID == 3)
                    //truot pv lan 1    
                    ds = wcfCR.CR_GetList(out itemCount, 3, keyWord, RecruitmentID, currPage, pageSize);
                     else if (_StatusID == 4)
                    //trung tuyen
                    ds = wcfCR.CR_GetList(out itemCount, 8, keyWord, RecruitmentID, currPage, pageSize);
                    DataTable dt = new DataTable();
                    dt = ds.Tables[0];
                    DataColumn dcol = new DataColumn("TRANGTHAI", typeof(string));
                    dt.Columns.Add(dcol);
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        switch (dt.Rows[i]["CR_STATUS"].ToString())
                        {
                            case "0":
                                dt.Rows[i]["TRANGTHAI"] = "Tất cả";
                                break;
                            case "1":
                                dt.Rows[i]["TRANGTHAI"] = "Nhập hồ sơ";
                                break;
                            case "2":
                                dt.Rows[i]["TRANGTHAI"] = "Phỏng vấn lần 1";
                                break;
                            case "3":
                                dt.Rows[i]["TRANGTHAI"] = "Trượt phỏng vấn lần 1";
                                break;
                            case "4":
                                dt.Rows[i]["TRANGTHAI"] = "Trúng tuyển";
                                break;
                        }

                    }
 
               
                if (ds.Tables.Count > 0)
                {
                    dt.Columns.Remove("CR_ID");
                    dt.Columns.Remove("CR_CandidateID");
                    dt.Columns.Remove("CR_RecruitmentID");
                    dt.Columns["Rownumber"].Caption = "STT";
                    dt.Columns["Candidate_No"].Caption = "Mã số";
                    dt.Columns["CANDIDATE_FIRSTNAME"].Caption = "Tên";
                    dt.Columns["CANDIDATE_LASTNAME"].Caption = "Họ đệm";
                    dt.Columns["CANDIDATE_FUlLNAME"].Caption = "Họ và tên";                       
                    dt.Columns["Candidate_Sex"].Caption = "Giới tính";
                    dt.Columns["Candidate_DateOfBirth"].Caption = "Ngày sinh";
                    dt.Columns["Candidate_PlaceOfBirth"].Caption = "Nơi sinh";
                    dt.Columns["Candidate_IDCardNo"].Caption = "CMTND";
                    dt.Columns["Candidate_Address"].Caption = "Địa chỉ";
                    dt.Columns["Candidate_Phone"].Caption = "Điện thoại";
                    dt.Columns["Candidate_Date"].Caption = "Ngày nộp hồ sơ";
                    dt.Columns["Recruitment_Name"].Caption = "Đợt tuyển dụng";
                    dt.Columns["TRANGTHAI"].Caption = "Trạng thái hồ sơ";
                    dt.Columns.Remove("CR_STATUS");
                    

                    ReadExcelFile.exportToExcelForEmployeeList("DANH SÁCH ỨNG VIÊN", "", "", ds, Path.GetTempPath() + "\\" + _fileName);

                    try
                    {
                        System.Diagnostics.Process.Start(Path.GetTempPath() + "\\" + _fileName);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Không mở được File \n" + Path.GetTempPath() + "\\" + _fileName, "Thông báo");
                    }

                }
            }
            catch (Exception)
            {
                MessageBox.Show("File " + Path.GetTempPath() + "\\" + _fileName + " đang được mở bằng một ứng dụng khác.\nHãy chọn file khác!", "Thông báo");
            }
        }

 

    }
}
